Skip to content

Switch to Microsoft.Extensions.Logging.Abstractions #191

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

Cheesebaron
Copy link

@Cheesebaron Cheesebaron commented Jun 17, 2021

This PR adresses the following:

  • Manage packages centrally instead of package version scattered all over the projects
  • Switch to Microsoft.Extensions.Logging.Abstractions + Serilog as the only dependencies for the library
  • Don't abuse the transitive dependency Microsoft.Extensions.Logging pulls in, such as Microsoft.Extensions.DependencyInjection to add DependencyInjection helpers, it should be more explicit then
  • Switch test projects to a modern net5.0 tfm
  • Update all dependencies to latest stable
  • Adds sourcelink support to the NuGet packages

Don't abuse the transitive dependency on DependencyInjection
@nblumhardt
Copy link
Member

Thanks for the PR! This seems like it would cause significant pain downstream - many consumers of this package use loggingBuilder.AddSerilog() - any thoughts on how that should be handled?

@Cheesebaron
Copy link
Author

Cheesebaron commented Jun 18, 2021

Yeah, maybe it should be added back, but by adding a explicit dependency on Microsoft.Extensions.DependencyInjection.

Alternatively, that should live in a different assembly, but that is not nice either.

EDIT:

Actually, ILoggingBuilder is only present in Microsoft.Extensions.Logging and not the abstractions. Would it be a huge issue if the dependency injection stuff lived in its own assembly?

The same goes for the ProviderFilter attribute I removed.

EDIT 2:

I've just pushed a new commit where I added a separate library for the extension. Let me know if this is the route you want to go.

@dkattan
Copy link

dkattan commented Jun 22, 2021

I don't know if it is related but we're about to completely dump Serilog over a MethodNotFound exception that seems to plague projects using the Microsoft Logging Abtractions. PowerShell/PowerShellEditorServices#1477

I happened across this pull request and perhaps it would solve our issues.

I haven't 100% nailed it down, but it appears that when a calling process is running .Net 5, AddSerilog() is simply not available.

The odd part is when I add the full csproj to my solution and mark it as a project dependency it is magically resolvable.

PowerShellEditorServices isn't directly importing this extension, but it calls OmniSharp which appears to be using it.

Thoughts?

@nblumhardt
Copy link
Member

@dkattan thanks for the ping. I think the tracking issue on the Serilog side is serilog/serilog-sinks-file#135 - will centralize discussion there.

@Cheesebaron
Copy link
Author

@dkattan you could as an experiment try grabbing the artifacts on the AppVeyor build here: https://ci.appveyor.com/project/serilog/serilog-framework-logging/builds/39654298 and see how that works out for you.

@@ -0,0 +1,16 @@
<Project>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project uses two-spaces indentation for other csprojs

<Project>
<ItemGroup>
<PackageVersion Include="Serilog" Version="2.10.0" />
<PackageVersion Include="Serilog.Sinks.Console" Version="3.1.1" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<PackageVersion Include="Serilog.Sinks.Console" Version="3.1.1" />
<PackageVersion Include="Serilog.Sinks.Console" Version="4.0.0" />

@@ -0,0 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New project containing only single file?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Cheesebaron If you want to get rid of Microsoft.Extensions.Logging/Microsoft.Extensions.DependencyInjection dependencies then look into MS sources :

 internal static class ProviderAliasUtilities
    {
        private const string AliasAttibuteTypeFullName = "Microsoft.Extensions.Logging.ProviderAliasAttribute";

        internal static string GetAlias(Type providerType)
        {
            foreach (CustomAttributeData attributeData in CustomAttributeData.GetCustomAttributes(providerType))
            {
                if (attributeData.AttributeType.FullName == AliasAttibuteTypeFullName)
                {
                    foreach (CustomAttributeTypedArgument arg in attributeData.ConstructorArguments)
                    {
                        Debug.Assert(arg.ArgumentType == typeof(string));

                        return arg.Value?.ToString();
                    }
                }
            }

            return null;
        }
    }

😉 I will not tell you exactly why they did that, but since they did it, then the reason was and why not use such a opportunity?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

изображение

@stphnlwlsh
Copy link

@nblumhardt I've started implementing Serilog using the Microsoft.Extensions.Logging package as well. We've got .NET 6 and Framework 4.7.1 projects that we're straddling, but want to introduce the common interfaces from Microsoft.

I've had to manually pick Microsoft.Extensions.Logging version 2.0.0 (deprecated) instead of 2.2.0. I can open a new issue/PR if need be, but thought this issue related: can we at the very least version bump to 2.2.0 ?

@nblumhardt
Copy link
Member

@stphnlwlsh a separate PR that addresses the dependency version only would be welcome - this PR is unlikely to move forward at this point due to the potential for breaking changes downstream. Thanks for the note!

@sungam3r sungam3r mentioned this pull request Mar 6, 2023
@sungam3r
Copy link
Contributor

sungam3r commented Mar 6, 2023

@stphnlwlsh a separate PR that addresses the dependency version only would be welcome - this PR is unlikely to move forward at this point due to the potential for breaking changes downstream. Thanks for the note!

@nblumhardt I suggest to close this abandoned PR since it mixes changes in CI with actual code changes. #214 upgrades the code base and CI without any actual code changes.

@sungam3r
Copy link
Contributor

sungam3r commented Mar 6, 2023

Of course switching to Microsoft.Extensions.Logging.Abstractions can be tracked by another issue if someone needs it.

@Cheesebaron Cheesebaron closed this Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants